{% extends "html/notebook/base.html" %}
{#
INPUT:
- worksheet - an instance of Worksheet
- notebook - an instance of Notebook which contains worksheet
- username - a string containing a username
#}

{% block javascript %}
<script src="/javascript/sage/js/published_worksheet.js"></script>
{% endblock %}

{% block page_id %}guest-worksheet-page{% endblock %}

{% set original_worksheet = worksheet.worksheet_that_was_published() %}
{% if original_worksheet.is_collaborator(username) or original_worksheet.is_owner(username) %}
    {% set edit_text = "Edit this." %}
    {% set edit_text = gettext('Edit this.') %}
{% elif notebook.user_manager().user_is_guest(username) %}
    {% set edit_text = gettext('Log in to edit a copy.') %}
    {% set url       = "/" %}
{% else %}
    {% set edit_text = gettext('Edit a copy.') %}
    {% set url       = "edit_published_page" %}
{% endif %}

{% set download_name = worksheet.download_name() %}

{% block body %}
<ul class="controls">
    <li><a href="{{ url }}">{{ edit_text }}</a></li>
    <li><a href="download/{{ download_name }}.sws">{{ gettext('Download.') }}</a></li>
    {% if worksheet.rating() != -1 or
       not (notebook.user_manager().user_is_guest(username) or worksheet.is_publisher(username)) %}
    <li>
        {% if worksheet.rating() != -1 %}
            <a class="usercontrol" href="rating_info">
                {{ gettext('This page is rated %(wr).1f.')|format(wr=worksheet.rating()) }}
            </a>
        {% endif %}
        {% if not (notebook.user_manager().user_is_guest(username) or worksheet.is_publisher(username)) %}
            <span>
            </span>
            {% for i in range(5) %}
            <input type="radio" name="rating" value={{ i }} > {{ i }}
            {% endfor %}
            &nbsp;&nbsp; <input name="rating_comment" id="rating_comment" value="{{ gettext('leave a comment') }}"/>
            <input type="button" id="rate_button" name="rating" value= {{ gettext("Rerate") if worksheet.is_rater(username) else gettext("Rate") }} > 
        {% endif %}
    </li>
    {% endif %}
    <li><a href="/pub/">{{ gettext('Other published documents...') }}</a></li>
</ul>
<hr class="usercontrol" />
<h1 class="title">{{ worksheet.name() }}</h1>
<h2 class="lastedit">{{ worksheet.html_time_since_last_edited() }}</h2>
{{ worksheet.html(do_print=false, publish=true, username=username) }}
<hr class="usercontrol" />
{% for i in range(10) %}
&nbsp;
{% endfor %}
{% endblock %}
